#define _CRT_SECURE_NO_WARNINGS 1
#include"SList.h"
SListNode* BuySListNode(SLTDateType x)
{
	SListNode* new = (SListNode*)malloc(sizeof(SListNode));
	if (new == NULL)
	{
		perror("malloc fail:");
		exit(-1);
	}
	new->data = x;
	new->next = NULL;
	return new;
}
void SListPushBack(SListNode** pplist, SLTDateType x)
{
	assert(pplist);
	SListNode* new = BuySListNode(x);
	SListNode* tail = *pplist;
	if (*pplist == NULL)
	{
		*pplist = new;
	}
	else
	{
		while (tail->next != NULL)
		{
			tail = tail->next;
		}
		tail->next = new;
	}
}
void SListPrint(SListNode* plist)
{
	SListNode* cur = plist;
	while (cur)
	{
		printf("%d ", cur->data);
		cur = cur->next;
	}
	printf("\n");
}
void SListPushFront(SListNode** pplist, SLTDateType x)
{
	assert(pplist);
	SListNode* new = BuySListNode(x);
	new->next = *pplist;
	*pplist = new;
}
void SListPopBack(SListNode** pplist)
{
	assert(pplist);
	assert(*pplist);
	SListNode* prev = NULL;
	SListNode* tail = *pplist;
	if ((*pplist)->next == NULL)
	{
		free(*pplist);
		*pplist = NULL;
	}
	else
	{
		while (tail->next)
		{
			prev = tail;
			tail = tail->next;
		}
		prev->next = NULL;
		free(tail);
		tail = NULL;
	}
}
void SListPopFront(SListNode** pplist)
{
	assert(pplist);
	assert(*pplist);
	SListNode* cur = (*pplist)->next;
	free(*pplist);
	*pplist = cur;
}
SListNode* SListFind(SListNode* plist, SLTDateType x)
{
	SListNode* cur = plist;
	while (cur)
	{
		if (cur->data == x)
		{
			return cur;
		}
		cur = cur->next;
	}
	return NULL;
}
//void SListInsertAfter(SListNode* pos, SLTDateType x)
//{
//	SListNode* new = BuySListNode(x);
//	new->next = pos->next;
//	pos->next = new;
//}